package app.server.project.main.service.controller;

import app.server.project.core.exception.SysError;
import app.server.project.core.http.RespModel;
import app.server.project.core.httpauth.UnAuth;
import app.server.project.core.token.TokenCache;
import app.server.project.core.util.AssertUtil;
import app.server.project.main.service.service.cms.GlobalCfgService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@AllArgsConstructor
@RestController
@RequestMapping("/globalcfg")
@Slf4j
public class GlobalCfgController {

    private final GlobalCfgService globalCfgService;

    /**
     * 上传客户端代码
     *
     * @param req
     */
    @UnAuth
    @PostMapping("/uploadImg/{userId}/{token}/{gId}")
    public RespModel uploadGame(@RequestParam("Fdata") MultipartFile files, @PathVariable long userId, @PathVariable String token, @PathVariable String gId) {
        AssertUtil.isTrue(TokenCache.chkToken(userId, token), SysError.ErrorToken);
        this.globalCfgService.uploadSingleImg(files, gId);
        return RespModel.success();
    }
}
